home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / pc / files / sat / msat09.tgz / CRC.C < prev    next >
Text File  |  1994-09-17  |  1KB  |  65 lines

  1. /*
  2.  *   Copyright 1992, 1993, 1994 John Melton (G0ORX/N6LYT)
  3.  *              All Rights Reserved
  4.  *
  5.  *   This program is free software; you can redistribute it and/or modify
  6.  *   it under the terms of the GNU General Public License as published by
  7.  *   the Free Software Foundation; either version 1, or (at your option)
  8.  *   any later version.
  9.  *
  10.  *   This program is distributed in the hope that it will be useful,
  11.  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *   GNU General Public License for more details.
  14.  *
  15.  *   You should have received a copy of the GNU General Public License
  16.  *   along with this program; if not, write to the Free Software
  17.  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  */
  20.  
  21. /*
  22.     crc.c
  23.  
  24.     CCITT CRC routines
  25.  
  26.     John Melton
  27.     G0ORX, N6LYT
  28.  
  29.     4 Charlwoods Close
  30.     Copthorne
  31.     West Sussex
  32.     RH10 3QZ
  33.     England
  34.  
  35.     INTERNET:    g0orx@amsat.org
  36.             n6lyt@amsat.org
  37.             john@images.demon.co.uk
  38.             J.D.Melton@slh0613.icl.wins.co.uk
  39.  
  40. */
  41.  
  42. int CheckCRC(unsigned char *buf, int length)
  43. {
  44.     unsigned short crc = 0;
  45.     int y, i;
  46.  
  47.     for (i = 0; i < length; i++)
  48.     {
  49.         crc ^= buf[i] << 8;
  50.  
  51.         for (y = 0; y < 8; y++)
  52.         {
  53.             if (crc & 0x8000)
  54.                 crc = crc << 1 ^ 0x1021;
  55.             else
  56.                 crc <<= 1;
  57.         }
  58.     }
  59.  
  60.     if (crc != 0)
  61.         return 0;
  62.     else
  63.         return 1;
  64. }
  65.